package init

import (
	"courier_srv/basic/config"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
)

func InRedis() {
	data := config.AppConf.Redis
	data_host := fmt.Sprintf("%s:%d", data.Host, data.Port)
	config.Rdb = redis.NewClient(&redis.Options{
		Addr:     data_host,
		Password: data.Password, // no password set
		DB:       data.DB,       // use default DB
	})

	_, err := config.Rdb.Ping(config.Ctx).Result()
	if err != nil {
		panic("redis init failed")
	} else {
		log.Println("redis init success")
	}

}
